<template>
  <el-dialog title="登录弹框" :visible.sync="dialogFormVisible">
    <el-form >
      <el-form-item label="用户名" :label-width="formLabelWidth">
        <el-input v-model="user.strUserName" ></el-input>
      </el-form-item>
      <el-form-item label="密码" :label-width="formLabelWidth">
       <el-input v-model="user.strPassWord" ></el-input>
      </el-form-item>
    </el-form>
   <div slot="footer" class="dialog-footer">
     <!-- <el-button @click="dialogFormVisible = false">取 消</el-button> -->
      <el-button type="primary" @click="login2">登录</el-button>
    </div>
  </el-dialog>
</template>

<script>

  export default{
    data(){
      return{
        user:{strUserName:'a',strPassWord:'b'},
        dialogFormVisible: true,
        formLabelWidth:'120px'
        }

      },
      methods: {
        login(){
          const url="http://localhost:8001/velidataPwd"
          this.$axios.get(url,{params:{strUserName:this.user.strUserName,strPassWord:this.user.strPassWord}}).then(res=>{
           // console.log(res.data)
            if(res.data==1){
              this.dialogFormVisible=false
            }else{
              this.$message.error('账号或者密码错误！')
            }

          }).catch(err=>{
            console.log(err)
          })

        },

        login2(){
          const url="http://localhost:8001/login"
          this.$axios.post(url,this.user).then(res=>{
           // console.log(res.data)
            if(res.data==1){
              this.dialogFormVisible=false
              //必须记录登录成功标记
              window.sessionStorage.setItem('storeData',res.data)
              //登录后跳转,必须使用路由
              this.$router.push('/index')//目标页面


            }else{
              this.$message.error('账号或者密码错误！')
            }

          }).catch(err=>{
            console.log(err)
          })

        }
      }

  }

</script>

<style>
</style>
